package com.mvc.base.service;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Service;

import com.mvc.base.model.Notice;
import com.mvc.framework.model.Auditable;
import com.mvc.framework.service.BaseService;
import com.mvc.framework.util.DateUtils;

@Service
public class NoticeManager extends BaseService<Notice, Long> {
	
	public List<Notice> getValidNotices(){
		StringBuilder sql = new StringBuilder(40);
		sql.append("SELECT A FROM ").append(Notice.class.getName());
		sql.append(" A WHERE A.recStatus= ? AND A.effectiveDate <= ? AND A.expireDate>= ? order by A.createdOn desc");
		Session session = getHibernateTemplate().getSessionFactory().openSession();
		Query query = session.createQuery(sql.toString()).setParameter(0, Auditable.REC_STATUS_VALID)
				.setParameter(1, DateUtils.getBeginOfCurrentDay())
				.setParameter(2, DateUtils.getEndOfCurrentDay());
		List<Notice>  result=query.list();
		session.close();
		return result;
	}
	
}
